package com.lq.ecoldchain.service

import android.app.Service
import android.content.Intent
import android.os.IBinder
import com.lq.ecoldchain.entity.EventAll
import com.lq.ecoldchain.internet.BaseObserver
import com.lq.ecoldchain.util.AMapUtils
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode

/*
*2019/1/16 0016  16:48
*定位 by lq
*/
class LocationService:Service(){
    override fun onBind(intent: Intent?): IBinder? {
        return null
    }

    override fun onCreate() {
        super.onCreate()
        EventBus.getDefault().register(this)
        AMapUtils.location()
    }

    @Subscribe(threadMode = ThreadMode.ASYNC)
    fun changePositionEvent(event:EventAll.LocationChangeEvent){
        BaseNetCore.ApiServiceImpl.updateCurrentCity(event.city).compose(RxTransformer.switchSchedulers()).subscribe(object:BaseObserver<String>(){
            override fun onSuccess(t: String?) {}
            override fun onFail(code: String) {}
        })
    }

    override fun onDestroy() {
        super.onDestroy()
        EventBus.getDefault().unregister(this)
    }

}